package com.lagou.service.Impl;

import com.lagou.base.Statuscode;
import com.lagou.dao.CourseDao;
import com.lagou.dao.Impl.CourseDaoImpl;
import com.lagou.pojo.Course;
import com.lagou.service.CourseService;
import com.lagou.utils.DateUtils;

import java.util.List;

public class CourseServiceImpl implements CourseService {
    CourseDao courseDao = new CourseDaoImpl();

    @Override
    public List<Course> findCourseList() {
        CourseDao courseDao = new CourseDaoImpl();
        List<Course> courseList = courseDao.findCourseList();

        return courseList;
    }
        @Override
        public List<Course> findCourseNameAndStatus (String course_name, String status){
            CourseDao courseDao = new CourseDaoImpl();
            List<Course> result = courseDao.findCourseNameAndStatus(course_name, status);

            return null;
        }

    @Override
    public String SaveCourseSales(Course course) {
        String dataFormart = DateUtils.getDateFormart();
        course.setCreate_time(dataFormart);
        course.setUpdate_time(dataFormart);
        course.setStatus(0);
        CourseDao courseDao = new CourseDaoImpl();
        int i = courseDao.SaveCourseSales(course);
        if (i > 0) {
            String result = Statuscode.SUCCESS.toString();
            return result;

        }else if(i<0){
            String result = Statuscode.FAIL.toString();
            return result;
        }

        return null;
    }

    @Override
    public List<Course> findCourseById(int id) {
        CourseDao courseDao = new CourseDaoImpl();
        List<Course> list = courseDao.findCourseById(id);
        return list;
    }
}
